<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="javascript，jquery," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="整理以前的笔记，在学习JavaScript时候,经常会用到一些方法，但是有时忘掉了具体用法，因此记下。方便以后查阅。这篇博文先说明这些方法的用途：removeClass()、remove()、css()  、prop() 、html()、appendTo() 、clone() 、parent() 、children()、nth-child(n)、even、odd 。 .addClass()   增">
<meta name="keywords" content="javascript，jquery">
<meta property="og:type" content="article">
<meta property="og:title" content="Jquery一些常用的方法">
<meta property="og:url" content="http://yoursite.com/2017/08/20/Jquery一些常用的方法/index.html">
<meta property="og:site_name" content="xuwujing&#39;s blog">
<meta property="og:description" content="整理以前的笔记，在学习JavaScript时候,经常会用到一些方法，但是有时忘掉了具体用法，因此记下。方便以后查阅。这篇博文先说明这些方法的用途：removeClass()、remove()、css()  、prop() 、html()、appendTo() 、clone() 、parent() 、children()、nth-child(n)、even、odd 。 .addClass()   增">
<meta property="og:updated_time" content="2017-08-31T11:06:12.362Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Jquery一些常用的方法">
<meta name="twitter:description" content="整理以前的笔记，在学习JavaScript时候,经常会用到一些方法，但是有时忘掉了具体用法，因此记下。方便以后查阅。这篇博文先说明这些方法的用途：removeClass()、remove()、css()  、prop() 、html()、appendTo() 、clone() 、parent() 、children()、nth-child(n)、even、odd 。 .addClass()   增">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/08/20/Jquery一些常用的方法/"/>





  <title>Jquery一些常用的方法 | xuwujing's blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?39c177d10f6e05ddfa113e02139b9c1c";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">xuwujing's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/20/Jquery一些常用的方法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="xuwujing">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/xuwujing.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="xuwujing's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Jquery一些常用的方法</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-20T13:20:00+08:00">
                2017-08-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/javascript/" itemprop="url" rel="index">
                    <span itemprop="name">javascript</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>整理以前的笔记，在学习JavaScript时候,经常会用到一些方法，但是有时忘掉了具体用法，因此记下。方便以后查阅。<br>这篇博文先说明这些方法的用途：<br>removeClass()、remove()、css()  、prop() 、html()、appendTo() 、clone() 、parent() 、children()、nth-child(n)、even、odd 。</p>
<h3 id="addClass-增加样式"><a href="#addClass-增加样式" class="headerlink" title=".addClass()   增加样式"></a>.addClass()   增加样式</h3><p>例如: $(“button”).addClass(“animated bounce”);  /<em>按钮做弹回效果 </em>/</p>
<h3 id="removeClass-移除样式"><a href="#removeClass-移除样式" class="headerlink" title=".removeClass()  移除样式"></a>.removeClass()  移除样式</h3><p>例如: $(“button”).removeClass(“btn-default”);  /<em>移除样式 </em>/  </p>
<h3 id="remove-移除元素"><a href="#remove-移除元素" class="headerlink" title=".remove()     移除元素"></a>.remove()     移除元素</h3><pre><code>例如:$(&quot;#target4&quot;).remove();   //移除按钮四所有的元素
</code></pre><h3 id="css-改变css样式"><a href="#css-改变css样式" class="headerlink" title=".css()     改变css样式"></a>.css()     改变css样式</h3><pre><code>例如: $(&quot;#target1&quot;).css(&quot;color&quot;, &quot;red&quot;); //按钮一改成了红色
</code></pre><h3 id="prop-调整元素属性"><a href="#prop-调整元素属性" class="headerlink" title=".prop()   调整元素属性"></a>.prop()   调整元素属性</h3><pre><code>例如:$(&quot;#target1&quot;).prop(&quot;disabled&quot;,true); //按钮一不可选
</code></pre><p>.html()   可以添加HTML标签和文字并替换掉之前的内容<br>例如:$(“#target4”).html(“<em>#TarGet4</em>“); //替换并增强文本</p>
<h3 id="appendTo-可以将选中的元素移到其他元素中"><a href="#appendTo-可以将选中的元素移到其他元素中" class="headerlink" title=".appendTo()  可以将选中的元素移到其他元素中"></a>.appendTo()  可以将选中的元素移到其他元素中</h3><pre><code>例如: $(&quot;#target2&quot;).appendTo(&quot;#right-well&quot;);  //将按钮二移动到右边
</code></pre><h3 id="clone-拷贝元素"><a href="#clone-拷贝元素" class="headerlink" title=".clone()   拷贝元素"></a>.clone()   拷贝元素</h3><pre><code>例如:$(&quot;#target5&quot;).clone().appendTo(&quot;#left-well&quot;);  //将按钮五拷贝到左边
</code></pre><h3 id="parent-访问父元素-上一级元素"><a href="#parent-访问父元素-上一级元素" class="headerlink" title=".parent()  访问父元素(上一级元素)"></a>.parent()  访问父元素(上一级元素)</h3><pre><code>例如:$(&quot;#target1&quot;).parent().css(&quot;background-color&quot;,&quot;red&quot;);//按钮一上一级的 背景颜色为红色
</code></pre><h3 id="children-子元素-下一级元素"><a href="#children-子元素-下一级元素" class="headerlink" title=".children()  子元素(下一级元素)"></a>.children()  子元素(下一级元素)</h3><pre><code>例如: $(&quot;#right-well&quot;).children().css(&quot;color&quot;,&quot;orange&quot;); //右边一下的元素都改成了橙色
</code></pre><h3 id="nth-child-n-通过CSS选择器索引顺序选择目标元素的子元素"><a href="#nth-child-n-通过CSS选择器索引顺序选择目标元素的子元素" class="headerlink" title=".nth-child(n)  通过CSS选择器索引顺序选择目标元素的子元素"></a>.nth-child(n)  通过CSS选择器索引顺序选择目标元素的子元素</h3><pre><code>例如:$(&quot;.target:nth-child(2)&quot;).addClass(&quot;animated bounce&quot;); //class 属性包含target 是添加元素
</code></pre><h3 id="even-偶数选择"><a href="#even-偶数选择" class="headerlink" title=".even   偶数选择"></a>.even   偶数选择</h3><pre><code>例如: $(&quot;.target:even&quot;).addClass(&quot;animated shake&quot;);  //获取class为target且索引为偶数的所有元素
</code></pre><h3 id="odd-奇数选择"><a href="#odd-奇数选择" class="headerlink" title=".odd   奇数选择"></a>.odd   奇数选择</h3><pre><code>例如:$(&quot;.target:odd&quot;).addClass(&quot;animated bounce&quot;);
</code></pre>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/javascript，jquery/" rel="tag"># javascript，jquery</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/08/19/Redis学习笔记之二 ：在Java项目中使用Redis/" rel="next" title="Redis学习笔记之二：在Java项目中使用Redis">
                <i class="fa fa-chevron-left"></i> Redis学习笔记之二：在Java项目中使用Redis
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/26/RabbitMQ消息队列之一：RabbitMQ的环境安装及配置/" rel="prev" title="RabbitMQ消息队列之一：RabbitMQ的环境安装及配置">
                RabbitMQ消息队列之一：RabbitMQ的环境安装及配置 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/xuwujing.png"
               alt="xuwujing" />
          <p class="site-author-name" itemprop="name">xuwujing</p>
           
              <p class="site-description motion-element" itemprop="description">The way of the future!</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">56</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">36</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xuwujing" target="_blank" title="github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  github
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://blog.csdn.net/qazwsxpcm?viewmode=list" target="_blank" title="csdn">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  csdn
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://home.cnblogs.com/u/xuwujing/" target="_blank" title="cnblogs">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  cnblogs
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.woainia.site/" title="woainia" target="_blank">woainia</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://cmsblogs.com/" title="chenssy" target="_blank">chenssy</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#addClass-增加样式"><span class="nav-number">1.</span> <span class="nav-text">.addClass()   增加样式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#removeClass-移除样式"><span class="nav-number">2.</span> <span class="nav-text">.removeClass()  移除样式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#remove-移除元素"><span class="nav-number">3.</span> <span class="nav-text">.remove()     移除元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#css-改变css样式"><span class="nav-number">4.</span> <span class="nav-text">.css()     改变css样式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#prop-调整元素属性"><span class="nav-number">5.</span> <span class="nav-text">.prop()   调整元素属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#appendTo-可以将选中的元素移到其他元素中"><span class="nav-number">6.</span> <span class="nav-text">.appendTo()  可以将选中的元素移到其他元素中</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#clone-拷贝元素"><span class="nav-number">7.</span> <span class="nav-text">.clone()   拷贝元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#parent-访问父元素-上一级元素"><span class="nav-number">8.</span> <span class="nav-text">.parent()  访问父元素(上一级元素)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#children-子元素-下一级元素"><span class="nav-number">9.</span> <span class="nav-text">.children()  子元素(下一级元素)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nth-child-n-通过CSS选择器索引顺序选择目标元素的子元素"><span class="nav-number">10.</span> <span class="nav-text">.nth-child(n)  通过CSS选择器索引顺序选择目标元素的子元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#even-偶数选择"><span class="nav-number">11.</span> <span class="nav-text">.even   偶数选择</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#odd-奇数选择"><span class="nav-number">12.</span> <span class="nav-text">.odd   奇数选择</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xuwujing</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
